<template>
	<div>
		<el-row :gutter="15">
			<el-form ref="bedRecord" :model="bedRecord" size="medium" label-width="101px" label-position="left">
				<el-col :span="12">
					<el-form-item label="档案编号" prop="recordNum">
						<el-input v-model="bedRecord.recordNum" placeholder="请输入档案编号" clearable
							:style="{width: '100%'}">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="姓名" prop="userName">
						<el-input v-model="bedRecord.userName" placeholder="请输入姓名" clearable :style="{width: '100%'}">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="性别" prop="sex">
						
						<el-select v-model="bedRecord.sex" placeholder="请选择性别" clearable :style="{width: '100%'}">
							<el-option v-for="(item, index) in sexData" :key="index" :label="item.label" :value="item.value"
								:disabled="item.disabled"></el-option>
						</el-select>
						
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label-width="139px" label="床位使用起始时间" prop="startDate">
						<el-date-picker v-model="bedRecord.startDate" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
							:style="{width: '100%'}" placeholder="请输入床位使用起始时间" clearable></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label-width="140px" label="床位结束使用时间" prop="eddingDate">
						<el-date-picker v-model="bedRecord.eddingDate" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
							:style="{width: '100%'}" placeholder="请输入床位结束使用时间" clearable></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="床位号" prop="bedInformation">
						
						<el-select v-model="bedRecord.bedInformation" placeholder="请选择床位"  clearable
							:style="{width: '100%'}">
							<el-option v-for="(item, index) in bedNumData" :key="index" :label="item.bedNum"
								:value="item.bedNum" :disabled="item.disabled"></el-option>
						</el-select>
						
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="标签" prop="state">
						<el-select v-model="bedRecord.state" placeholder="请选择状态"  clearable
							:style="{width: '100%'}">
							<el-option v-for="(item, index) in stateOptions" :key="index" :label="item.label"
								:value="item.value" :disabled="item.disabled"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<div slot="footer">
			<el-button type="primary" @click="save">确定</el-button>
			<el-button @click="close">取消</el-button>
		</div>
	</div>
</template>
<script>
	export default {
		name: 'BedRecordEdit',
		props: ['editid'],
		data() {
			return {
				bedRecord: {
					BedId:'',
					recordNum: undefined,
					userName: undefined,
					sex: undefined,
					startDate: undefined,
					eddingDate: undefined,
					bedInformation: undefined,
					state:"正常"
				},
				stateOptions: [{
					"label": "正常",
					"value": "正常"
				}, {
					"label": "离开",
					"value": "离开"
				}, {
					"label": "退住",
					"value": "退住"
				}],
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				bedNumData: [],
				url: '/bedRecord/save'
			}
		},
		computed: {},
		watch: {},
		created() {
			if (this.editid) {
				// 通过id 读原始数据
				this.axios.get('/bedRecord/getById', response => {
					this.bedRecord = response.obj;
					this.url='/bedRecord/update';
				}, {
					id: this.editid
				})
			}
			this.axios.get('/bed/getlist', res => {
				this.bedNumData = res.obj;
			})
			
		},
		mounted() {},
		methods: {
			save() {
				this.$refs['bedRecord'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false);
							this.$emit('update:editid', null);
							this.$emit('getData');
						}, this.bedRecord)
					}
				})
			},
			close(){
				this.$emit('update:show',false);
			}


		}
	}
</script>
<style>
	.paper{
		width: 100%;
		
	}
</style>
